Skip to content

[fix,refactor] Remove SimpleStorageUnit ZMQ proxy hop and per-request thread resets - #228

Merged
0oshowero0 merged 5 commits into
Ascend:mainfrom
0oshowero0:refactor/storage-plane-split
Nov 26, 2026
Merged

0oshowero0 merged 5 commits into
Ascend:mainfrom
0oshowero0:refactor/storage-plane-split

Conversation

@0oshowero0

@0oshowero0 0oshowero0 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Simplify SimpleStorageUnit's ZMQ serving path, eliminate per-request PyTorch thread-count resets, unify GET heavy-operation logging on the client side, and harden worker fault isolation.

Changes

  • Direct ROUTER worker loop (transfer_queue/storage/simple_storage.py):
    • Poll the bound ROUTER socket directly from SimpleStorageUnit's single worker thread (retaining STORAGE_CLIENT_IDENTITY_PREFIXES filtering), removing proxy_thread, the inproc:// DEALER socket, two redundant ZMQ forwarding hops per request, and the hardcoded 0.5s startup sleep.
  • Worker-thread PyTorch parallelism initialization (transfer_queue/utils/common.py, simple_storage.py):
    • Extract set_pytorch_auto_parallel_threads() and call it once at _worker_routine startup instead of reading CPU topology (psutil.cpu_count(logical=False)) and toggling torch.set_num_threads() on every storage request.
  • Unified client-side heavy-operation logging (zmq.py, simple_storage_manager.py, simple_storage.py):
    • Populate PayloadReply.wire_bytes for GET responses in ZmqPayloadTransfer.request and invoke log_heavy_operation() uniformly for PUT, UPDATE, and GET in AsyncSimpleStorageManager._request_payload, removing the GET-specific server-side logging branch.

Reliability Improvements

  • Preserve queued concurrent requests on pre-send worker errors: Previously, _proxy_routine eagerly drained incoming requests into worker_socket's inproc:// pipe, so closing and recreating worker_socket(linger=0) on any unhandled per-request error silently dropped sibling requests already buffered in that pipe (including single-attempt operations such as UPDATE and CLEAR_DATA). Materializing all reply zmq.Frame views before touching put_get_socket keeps the ROUTER socket intact on pre-send errors so queued sibling requests continue to be served.
  • Prevent reply misrouting on mid-SNDMORE failures: _send_multipart_reply validates and wraps all frames before queuing the routing identity with zmq.SNDMORE. If send() fails after a non-final SNDMORE frame has already entered put_get_socket, _router_tainted escalates to _abort_process so the next peer's reply can never be appended to an unfinished multipart envelope, while ZMTP's atomic multipart delivery discards uncommitted frames on the client.
  • Fail fast instead of busy-spinning on unrecoverable poller errors: Replace the blanket except Exception: continue around poller.poll() in _worker_loop with EINTR-only retry (and clean exit during shutdown) so fatal ZMQErrors (e.g. ENOTSOCK) trigger _abort_process immediately rather than spinning in a live-looking unresponsive actor.
  • Eliminate startup readiness race: Serving the bound ROUTER socket directly removes the inproc:// connect ordering assumption previously papered over by a hardcoded 0.5s startup sleep.
  • Fix ARM64 / container CPU core fallback and thread isolation: Fall back to psutil.cpu_count(logical=True) or os.cpu_count() or 1 when psutil.cpu_count(logical=False) returns None (avoiding TypeError on main and preventing silent clamping to 1 thread on ARM64/containerized hosts where physical core topology is unexposed), and configure ATen/OpenMP threads on worker_thread itself without mutating the caller's main thread during in-process instantiation.

Performance

On the same CPU host with the Python controller, median kv_batch_put latency fell by 38% and kv_batch_get latency by 28% from the pre-PR baseline. Each batch contained 128 rows with four fields of 1,024 float32 values per row.

Benchmark (median PUT / GET latency, ms) Baseline a906942 Earlier PR revision 77687f6 This revision a8c49e7
Public batch API, same host 11.83 / 18.20 7.67 / 13.57 7.30 / 13.14
Storage round trip, 4 KiB 3.14 / 3.18 0.170 / 0.171 0.168 / 0.166
Storage round trip, 4 MiB 4.06 / 4.11 0.783 / 0.790 0.771 / 0.757
GitHub CI, Python controller 8.69 / 17.75 6.98 / 12.13 7.79 / 13.32
GitHub CI, Rust controller 9.51 / 21.60 7.17 / 12.87 8.60 / 15.44

The same-host batch results combine 48 measurements per operation and revision across two runs after warm-up. The storage round trips used one request at a time over loopback TCP. Each table entry for those tests is the median of three run medians.

CI medians use the final three of four iterations. Compared with 77687f6, CI recorded 10–20% higher latency on a8c49e7. In the same-host Python batch test, median PUT and GET latency fell by 4.8% and 3.2%, respectively. Baseline CI · Earlier revision CI · This revision CI

Validation

  • 173 unit tests passing across test_zmq_payload_transfer.py, test_storage_request_retry.py, test_storage_key_race.py, test_accept_probe.py, test_storage_worker_death_exits.py, test_async_simple_storage_manager.py, test_simple_storage_unit.py, and test_data_dump.py.
  • ruff format --check, ruff check, mypy --no-site-packages transfer_queue, check_docstrings.py, and check_license.py pass.

…ead resets

- Poll the bound ROUTER socket directly from the single SimpleStorageUnit worker thread (preserving STORAGE_CLIENT_IDENTITY_PREFIXES filtering), removing proxy_thread, inproc worker_socket, and the 0.5s startup sleep

- Configure PyTorch CPU parallelism once in SimpleStorageUnit.__init__ via set_pytorch_auto_parallel_threads rather than reading /proc/cpuinfo and mutating process-global torch.set_num_threads on every request

- Populate GET reply wire_bytes in ZmqPayloadTransfer.request and unify heavy-operation logging for PUT, UPDATE, and GET on the client side in AsyncSimpleStorageManager._request_payload

Signed-off-by: 0oshowero0 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T05:29:39.736557Z 77e0076 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…nd exit on poll faults

- Replace empty-frame flushing on mid-reply errors with closing and rebinding the ROUTER socket so uncommitted multipart frames are rolled back rather than delivered incomplete

- Validate decoded tensor and NumPy buffer byte lengths against shape * itemsize in serial_utils so truncated or empty frames never materialize uninitialized arrays

- Propagate unrecoverable ZMQ poller errors (e.g. ENOTSOCK) to _abort_process instead of spinning in _worker_loop

Signed-off-by: 0oshowero0 <[email protected]>
…read fallback

- Remove _rebind_router_socket and pre-construct zmq.Frame buffers before sending so pre-send errors keep queued concurrent requests intact while mid-SNDMORE failures exit cleanly via _abort_process

- Revert per-tensor serial_utils decode size check to restore baseline decode throughput

- Fall back to logical/OS CPU count when psutil.cpu_count(logical=False) is None on ARM64/containers, set PyTorch threads inside _worker_routine, and clean up stale proxy comments

Signed-off-by: 0oshowero0 <[email protected]>
@0oshowero0 0oshowero0 changed the title [refactor] Remove SimpleStorageUnit ZMQ proxy hop and per-request thread resets [fix,refactor] Remove SimpleStorageUnit ZMQ proxy hop and per-request thread resets Nov 26, 2026
@0oshowero0
0oshowero0 merged commit 59a95a7 into Ascend:main Nov 26, 2026
16 checks passed
0oshowero0 pushed a commit that referenced this pull request Nov 26, 2026
After #228 moved SimpleStorage worker thread configuration to startup,
the client still queries CPU topology on every async_put() and
async_get_data() call through limit_pytorch_auto_parallel_threads().

Cache the CPU count once at module import to remove these repeated
queries from the client-side data transfer paths. he cached count
assumes CPU topology remains stable during runtime.

Previously tested on a verl ref worker: tq.get() time 5.69s → 0.23s per
step; tq.put() time 6.28s → 1.52s per step.

@renjunying2

Signed-off-by: dodatboii <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant